import requestMeeting, { request } from '@/plugins/axios'
import { ApplyMsgItem, FetchOpsApi, SystemInfoItem } from './interface'
import { transSystemInfo } from './translator'

export const fetchOps = async (meetingMoid: string) =>
	request<FetchOpsApi>({
		url: `/api/inner/ops/diagnose/conf/${meetingMoid}/real_time/`,
		method: 'get',
	}).then((res) => (res.success && res.info ? res.info : undefined))

export const fetchSysMsg = async (meetingMoid: string) =>
	requestMeeting<SystemInfoItem[]>({
		url: `/mcc/${meetingMoid}/sysmsg`,
		method: 'get',
	}).then((res) => (res.success && res.data ? res.data.map((x) => transSystemInfo(x)) : undefined))

/** 同意操作 */
export const fetchAccept = async (id: string) =>
	requestMeeting({
		url: `/mcc/sysmsg/${id}`,
		method: 'post',
		data: {},
	}).then((res) => res)

/** 获取终端申请列表  state: 1-待审批，2-同意 3-拒绝 不传获取全部，可，分隔多个 */
export const fetchApplyMsg = async (meetingMoid: string, param?: { state: 1 | 2 | 3 }) =>
	request<{ mt_applys: ApplyMsgItem[] }>({
		url: `/mcc/${meetingMoid}/mt_applys`,
		method: 'get',
		params: param,
	}).then((res) => (res.success && res.mt_applys ? res.mt_applys : undefined))

/** 审批操作 mt_id: mt_id如果没有的话（终端离会）就下account  state: 2-同意 3-拒绝*/
export const fetchApplyOperate = async (
	meeting_moid: string,
	mt_id: string,
	mt_apply_moid: string,
	data: { state: 2 | 3 }
) =>
	requestMeeting({
		url: `/mcc/${meeting_moid}/mts/${mt_id}/mt_applys/${mt_apply_moid}`,
		method: 'put',
		data: data,
	}).then((res) => res)
